#include "modifyinfo.h"
#include "ui_modifyinfo.h"
#include "ClientSocket.h"
#include "vector_serialization.h"
#include<iostream>
#include<QMessageBox>

modifyinfo::modifyinfo(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::modifyinfo)
{
        ui->setupUi(this);
        connect(ui->pushButton_modify, SIGNAL(clicked()),
                this, SLOT(handleModify()));
}

modifyinfo::~modifyinfo()
{
        delete ui;
}

void modifyinfo::handleModify() {
        std::string sendmsg, reply;
        std::string oldname = ui->lineEdit_uname->text().toStdString();
        std::string uname = ui->lineEdit_newname->text().toStdString();
        std::string upasswd = ui->lineEdit_newpasswd->text().toStdString();
        std::string urole = ui->comboBox_newrole->currentText().toStdString();
        if (!urole.compare("工作人员"))
                urole = "w";
        else
                urole = "m";
        map<std::string, std::string> smap;
        smap["code"] = "004";
        smap["oldname"] = oldname;
        smap["uname"] = uname;
        smap["upasswd"] = upasswd;
        smap["urole"] = urole;
        sendmsg = save(smap);
        ClientSocket client_socket("localhost",30000);
        client_socket << sendmsg;
        client_socket >> reply;
        QMessageBox::about(0,"reply:",QString::fromStdString(reply));
        this->close();
}
